<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */

/**
 * Member gateway class for communicating with persistent storage
 */
class Core_Gateway_Access extends RedCross_Gateway_GatewayAbstract
{
    /**
     * Constructor
     * Defines some private variables
     */
    public function __construct()
    {
        $this->_class = 'Access';
        $this->_modelPath = 'Core_Model';
    }

    public function fetchAllAccess($paginate = false)
    {
        $query = Doctrine_Query::create()
            ->select()
            ->from($this->getModelClass() . ' c');
        return $query->execute();
    }

    public function fetchMembersWithAccess($accessId) {
        $query = Doctrine_Query::create()
            ->select()
            ->from('Core_Model_Member m')
            ->leftJoin('m.MemberAccess ma')
            ->where('ma.access_id = ?', $accessId)
            ->andWhere('ma.lost_access_date IS NULL');
        return $query->execute();
    }
}
